<!-- begin manage_category_list.html -->
<script type="text/javascript">
var g_app = '${app}';
var g_command = '${command}';
var g_count = $categories.__len__();
var MAX = 20;
//#raw
$(function() {
    if (g_count>=MAX) {
		$('#add').attr('disabled', 'disabled');
		set_warning('You have reached the limitation of maximum categories.');
	}
    $('#add').click(function() {
        location.assign('/manage/?app=' + g_app + '&command=' + g_command + '&btn=add');
    });
});
function submit_form(btn, id) {
	if (btn=='delete') {
		if (!confirm('Are you sure you want to delete this category permanently?')) {
			return;
		}
	}
    $('#btn').val(btn);
    $('#id').val(id);
    $('#edit_form').submit();
}
$(function() {
    $('#delete').click(function() {
        var selected_cs = $('input.select-c:checked');
        if (selected_cs.length==0) {
			alert('Please select categories first.');
		}
		else if (selected_cs.length==$('input.select-c').length) {
            alert('You cannot delete all categories.');
		}
		else {
			var msg = 'Are you sure you want to delete this category?';
			if (selected_cs.length>1) {
				msg = 'Are you sure you want to delete these categories?';
			}
			if (confirm(msg)) {
				$('#btn').val('delete');
				$('#edit_form').submit();
			}
		}
    });
    $('#select_all').change(function() {
        if ($('#select_all').is(':checked')) {
            $('.select-c').attr('checked', 'checked');
            $('.tr-hover').addClass('tr-selected');
        }
        else {
            $('.select-c').removeAttr('checked');
            $('.tr-hover').removeClass('tr-selected');
        }
    });
    $('.select-c').click(function() {
        if ($(this).is(':checked')) {
            $(this).parent().parent().parent().addClass('tr-selected');
        }
        else {
            $(this).parent().parent().parent().removeClass('tr-selected');
        }
        if ($('input.select-c:checked').length==$('input.select-c').length) {
            $('#select_all').attr('checked', 'checked');
        }
        else {
            $('#select_all').removeAttr('checked');
        }
	});
});
//#end raw
</script>

<div class="panel box-round">
  <div class="panel-title"><div>All Categories</div></div>
  <div class="panel-content">
  <form id="edit_form" action="/manage/" method="post">
  	<input type="hidden" name="app" value="${app}" />
  	<input type="hidden" name="command" value="${command}" />
  	<input type="hidden" id="btn" name="btn" value="" />
  	<input type="hidden" id="id" name="id" value="" />
    <div class="th bottom-line">
      <div class="span-1"><div><input type="checkbox" id="select_all" name="select_all" /></div></div>
      <div class="span-10"><div>Name</div></div>
      <div class="span-7"><div>Description</div></div>
      <div class="span-2 last"><div>Posts</div></div>
    </div>
  #for $c in $categories
    <div class="tr tr-hover">
      <div class="span-1"><div><input type="checkbox" name="u" class="select-c" value="${c.id}" /></div></div>
      <div class="span-10">
      	<div style="font-weight:bold">
          <a href="?app=${app}&command=${command}&btn=edit&id=${c.id}">${c.name}</a>
        </div>
        <div>
          <a href="?app=${app}&command=${command}&btn=edit&id=${c.id}">Edit</a> | <a href="javascript:submit_form('delete', '${c.id}')">Delete</a> | <a href="/blog/cat/${c.id}" target="_blank">View</a>
		</div>
      </div>
      <div class="span-7"><div>${c.description}</div></div>
      <div class="span-2 last"><div>0</div></div>
    </div>
  #end for
  	<div class="tr top-line">
      <div class="span-19 last">
        <div>
          <button type="button" name="add" id="add">Add New</button>
          <button type="button" name="delete" id="delete">Delete</button>
        </div>
      </div>
  	</div>
  </div>
  </form>
</div>
<!-- end manage_category_list.html -->
